<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

    <title>视频网站轮播图</title>

    <style>
        * {
            /* 初始化 */
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            /* 100%窗口宽高 */
            height: 100vh;
            /* 弹性布局 居中显示 */
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f4f4f4;
        }

        .container {
            width: 100%;
            height: 592px;
            position: relative;
        }

        /* 容器四边的渐变黑 */
        .shades {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            /* 元素不对指针事件做出反应 */
            pointer-events: none;
        }

        .shades .left {
            width: 160px;
            height: 100%;
            background: linear-gradient(to left, transparent, #16161a);
            position: absolute;
            left: 0;
            top: 0;
        }

        .shades .right {
            width: 160px;
            height: 100%;
            background: linear-gradient(to right, transparent, #16161a);
            position: absolute;
            right: 0;
            top: 0;
        }

        .shades .top {
            width: 100%;
            height: 90px;
            background: linear-gradient(to top, transparent, #16161a);
            position: absolute;
            left: 0;
            top: 0;
        }

        .shades .bottom {
            width: 100%;
            height: 220px;
            background: linear-gradient(to bottom, transparent, #16161a);
            position: absolute;
            left: 0;
            bottom: 0;
        }

        .imgs {
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
        }

        .imgs img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            object-position: center;
            position: absolute;
        }

        .imgs a {
            opacity: 0;
            transition: 0.2s;
        }

        .imgs a.active {
            opacity: 1;
        }

        .titles {
            width: 297px;
            height: 416px;
            position: absolute;
            top: 19%;
            right: 5%;
            background: linear-gradient(to bottom, transparent, #16161a 22%, #16161a 81%, transparent);
        }

        .titles a {
            display: block;
            color: rgba(255, 255, 255, 0.6);
            text-decoration: none;
            width: 100%;
            padding: 12px 20px;
        }

        .titles .title2 {
            font-size: 12px;
            margin-top: 8px;
            font-weight: normal;
            /* 副标题默认隐藏 */
            display: none;
        }

        /* 标题活动态 */
        .titles a.active {
            color: #fff;
            font-size: 20px;
            font-weight: bold;
            background: linear-gradient(to right, rgba(255, 255, 255, 0.25) 20%, transparent 90%);
        }

        .titles a.active .title2 {
            /* 活动态下副标题显示 */
            display: block;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="imgs">
            <a href="#" class="active">
                <img src="https://tse2-mm.cn.bing.net/th/id/OIP-C.yG6vOvuyOPqu_yTxfGf6RgHaEL?pid=ImgDet&rs=1" alt="">
            </a>
            <a href="#">
                <img src="https://n.sinaimg.cn/sinakd202167s/122/w1080h642/20210607/3238-kracxer3330867.jpg" alt="">
            </a>
            <a href="#">
                <img src="https://tse4-mm.cn.bing.net/th/id/OIP-C.CEzv3vE18i0C7DeFWl9jVQHaEK?w=308&h=180&c=7&r=0&o=5&dpr=1.3&pid=1.7"
                    alt="">
            </a>
            <a href="#">
                <img src="https://pic1.zhimg.com/v2-8a7c81a6869ba579acbfa575d792627f_r.jpg?source=1940ef5c" alt="">
            </a>
            <a href="#">
                <img src="https://pic.dmjnb.com/pic/8cf2d48a23ee923f3b23ec495de1fbf4?imageMogr2/thumbnail/x380/quality/90!"
                    alt="">
            </a>
            <a href="#">
                <img src="https://pic.dmjnb.com/pic/05f2c0b30320d66633b9267658e48dea?imageMogr2/thumbnail/x380/quality/90!"
                    alt="">
            </a>
            <a href="#">
                <img src="https://p1.ssl.qhimg.com/t013e393fa0b52c020f.jpg" alt="">
            </a>
            <a href="#">
                <img src="https://puui.qpic.cn/vpic_cover/k3361x88jzo/k3361x88jzo_old_ori.jpg/s640x360" alt="">
            </a>
        </div>
        <div class="shades">
            <div class="left"></div>
            <div class="top"></div>
            <div class="right"></div>
            <div class="bottom"></div>
        </div>
        <div class="titles">
            <a href="#" class="active">
                <div class="title">照亮你</div>
                <div class="title2">磕血糖!张若楠重灾区救援陈伟霆</div>
            </a>
            <a href="#">
                <div class="title">萌探探探案3</div>
                <div class="title2">孙红雷曾志伟大佬对决</div>
            </a>
            <a href="#">
                <div class="title">狂飙</div>
                <div class="title2">张译张颂文黑白较量</div>
            </a>
            <a href="#">
                <div class="title">新猫和老鼠 第4季</div>
                <div class="title2">现代版全新猫鼠4</div>
            </a>
            <a href="#">
                <div class="title">奔跑吧第7季</div>
                <div class="title2">baby周深解锁奇幻之旅</div>
            </a>
            <a href="#">
                <div class="title">极限挑战第9季</div>
                <div class="title2">岳云鹏严浩翔历9弥新</div>
            </a>
            <a href="#">
                <div class="title">中国新说唱</div>
                <div class="title2">加更！邓典果黄旭殊死一搏</div>
            </a>
            <a href="#">
                <div class="title">公诉</div>
                <div class="title2">迪丽热巴，佟大为 反诈题材</div>
            </a>
        </div>
    </div>

    <script>
        //    获取图片和标题标签
        const imgs = document.querySelectorAll(".imgs a")
        const titles = document.querySelectorAll(".titles a")
        // 设置计数器和定时器
        let curIndex = 0, timer = null;

        // 首先清除图片和标题的active样式
        function removeActive() {
            titles.forEach(item => {
                item.classList.remove("active")
            })
            imgs.forEach(item => {
                item.classList.remove("active")
            })
        }

        // 切换banner
        function changeBanner(index) {
            removeActive()
            titles[index].classList.add("active")
            imgs[index].classList.add("active")
        }

        autoBanner()
        // 自动播放
        function autoBanner() {
            timer = setInterval(function () {
                curIndex++;
                if (curIndex > titles.length - 1) {
                    curIndex = 0
                }
                changeBanner(curIndex)
            }, 2000)
        }

        // 设置鼠标移入移出事件
        titles.forEach((item, index) => {
            item.addEventListener("mouseenter", function () {
                curIndex = index;
                clearInterval(timer)
                changeBanner(index)
            })
            item.addEventListener("mouseleave", function () {
                autoBanner()
            })
        })
    </script>
</body>

</html>